package model.resource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.effect.TeleportEffect;
import model.entity.BasicEntity;
import model.entity.Entity;
import model.entity.NPC;
import model.item.Item;
import model.map.GameMap;
import model.map.Location;
import model.map.World;



/**
 * 
 *
 * This class is used to map an NPC to its battleLoader (for the battle map)
 * along with loading the map.
 *
 */

public class NPCBattleLoader{

	public List<BasicEntity> npcs;
	public Map<Location, Item> items;
	public Location avatarSpot;
	GameMap battleMap;
	
	public NPCBattleLoader(){
		npcs = new ArrayList<BasicEntity>();
		items = new HashMap<Location, Item>();
		avatarSpot = new Location();
		battleMap = World.getInstance().getBattleMap();
	}
	
	public void setAvatarSpot(Location loc){
		avatarSpot = loc;
	}
	
	public void addPair(NPC npc){
		npcs.add(npc);
	}
	
	public void addPair(Item it, Location loc){
		items.put(loc, it);
	}
	
	/**
	 * populates the battle map
	 */
	public void load(){
		// teleport the avatar to the battleMap
		TeleportEffect te = new TeleportEffect("tpotToBattleMap", battleMap.getName(), avatarSpot);
		te.doEffect(World.getInstance().getPlayer());
		
		// put npcs in battle map
		for (BasicEntity npc : npcs){
			battleMap.addEntity(npc);	
		}
		
		// put items in the battle map
		for (Location loc : items.keySet()){
			battleMap.addItem(loc, items.get(loc));
		}
	}
}